package world.liuru.poem.controller;

import org.springframework.web.bind.annotation.*;
import world.liuru.poem.entity.Poem;
import world.liuru.poem.service.PoemService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/poem")
public class PoemController {

    @Resource
    PoemService poemService;

    @PostMapping("")
    public Poem addPoem(@RequestBody Poem poem){
        return poemService.insertPoem(poem);
    }

    @DeleteMapping("/{id}")
    public void deletePoem(@PathVariable("id") String id){
        poemService.deletePoem(id);
    }

    @PutMapping("")
    public Poem updatePoem(@RequestBody Poem poem){
        return poemService.updatePoem(poem);
    }

    @GetMapping("")
    public List<Poem> findAll(){
        return poemService.findAllPoem();
    }

    @GetMapping("/{id}")
    public Poem findById(@PathVariable("id") String id){
        return poemService.findPoemById(id);
    }


}
